window.onload=function(){
	mui.init({
			swipeBack:true, //启用右滑关闭功能
			gestureConfig:{
			   tap: true, //默认为true
			   doubletap: true, //默认为false
			   longtap: true, //默认为false
			   swipe: true, //默认为true
			   drag: true, //默认为true
			   hold:false,//默认为false，不监听
			   release:false//默认为false，不监听
		}
	});
	//兄弟元素查找
	function siblings(elm) {
		var a = [];
		var p = elm.parentNode.children;
		for(var i =0,pl= p.length;i<pl;i++) {
			if(p[i] !== elm) a.push(p[i]);
		}
		return a;
	}
	//console.log(jQuery('[name=guige]').onclick());
	//没有规格直接加入购物车
	jQuery("#striAdd").click(function(){
		var spac_list = jQuery('.spac-list');console.log(spac_list);
		if(spac_list.length==0){
			add_to_cart();
		}
	});

	//选择规格处理逻辑
	document.getElementsByClassName('cart-toggle-center')[0].onclick=function(event){

		var event = window.event || arguments.callee.caller.arguments[0];

		var targetObj = event.srcElement || event.target;
		if(targetObj.className=='guige') {
			var p = targetObj.parentNode.children;
			for(var i =1,pl= p.length;i<pl;i++) {
				p[i].style.border="2px solid grey";
			}
			targetObj.style.border = '2px solid red';

			var guigeAll = document.getElementsByClassName('guige');
			var content = '';
			var attr_id = new Array();
			for(var i =0,pl= guigeAll.length;i<pl;i++) {
				if(guigeAll[i].style.border=="2px solid red"){
					content += guigeAll[i].parentNode.children[0].innerHTML+':'+guigeAll[i].innerText+'&';
					attr_id.push(guigeAll[i].children[0].value);
				}
			}
			var inputId= document.getElementById('guige-genaral');
			var content=content.substring(0,content.length-1);
			var attrIds= document.getElementById('attr-ids');
			inputId.value = content;
			attrIds.value = attr_id;
		}
	}
	//loading(1000);


	// 格式化两位数
	function fix(num, length) {
		return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num;
	}

	// 倒计时
	var promote_end_date = document.querySelector("#promote_end_date").value;
	function GetRTime(){
		var EndTime= new Date(promote_end_date);
		var NowTime = new Date();
		var t =EndTime.getTime() - NowTime.getTime();
		var d=0;
		var h=0;
		var m=0;
		var s=0;
		if(t>=0){
			d=Math.floor(t/1000/60/60/24);
			h=Math.floor(t/1000/60/60%24);
			m=Math.floor(t/1000/60%60);
			s=Math.floor(t/1000%60);
		}
		h  = fix(h, 2);
		m  = fix(m, 2);
		s  = fix(s, 2);
		document.querySelector(".active-info-time").innerHTML = 
		'距结束还剩:<br /><em>'+h+'</em>:<em>'+m+'</em>:<em>'+s+'</em>';
	}
	setInterval(GetRTime,1000);

	// 页面拖动事件，改变促销信息样式
	//mui("body")[0].addEventListener("drag",function(){
	//	// var footer = document.getElementsByTagName('footer')[0];
	//	// if(getScrollTop() + getWindowHeight()+40 > getScrollHeight()){
	//	// 	   footer.style.position = 'relative';
	//	// }else{
	//	// 	footer.style.position = 'fixed';
	//	// }
	//	var gudingHeght = document.getElementById('slider').offsetHeight;
	//	var info = document.getElementsByClassName('active-info')[0];
	//	if(typeof(info)=='undefined'){
	//		var info = document.getElementsByClassName('active-info-change')[0];
	//	}
	//	if(parseInt(getScrollTop())>(parseInt(gudingHeght)-44)){
	//		removeClass(info,'active-info');
	//		addClass(info,'active-info-change');
	//	}else{
	//		addClass(info,'active-info');
	//		removeClass(info,'active-info-change');
	//	}
	//})

	// 获取滚条卷上去的高度
	function getScrollTop() {  
		var scrollTop;  
		// 兼容IE
		scrollTop = window.pageYOffset|| document.documentElement.scrollTop || document.body.scrollTop;
		return scrollTop;   
	} 

	//获取文档总高度
	function getScrollHeight(){
	　　var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
	　　if(document.body){
	　　　　bodyScrollHeight = document.body.scrollHeight;
	　　}
	　　if(document.documentElement){
	　　　　documentScrollHeight = document.documentElement.scrollHeight;
	　　}
	　　scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
	　　return scrollHeight;
	}

	//浏览器视口的高度
	function getWindowHeight(){
	　　var windowHeight = 0;
	　　if(document.compatMode == "CSS1Compat"){
	　　　　windowHeight = document.documentElement.clientHeight;
	　　}else{
	　　　　windowHeight = document.body.clientHeight;
	　　}
	　　return windowHeight;
	}

}